﻿using CommonNet48.SerializerUtils;
using DBOptionPro.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBOptionPro.BLL
{
    /// <summary>
    /// 地区信息业务逻辑处理类
    /// </summary>
    public class AreaBLL
    {
        /// <summary>
        /// 地区配置文件路径(可以通过百度json在线格式化工具格式化后进行自行增加减少配置。)
        /// </summary>
        private readonly string _File = Path.Combine(AppContext.BaseDirectory, "Config", "Area.json");

        private List<MyArea> _Areas;

        /// <summary>
        /// 获取所有地区信息
        /// </summary>
        /// <returns></returns>
        public List<MyArea> GetAreas()
        {
            if (_Areas == null)
            {
                _Areas = JsonHelper.JsonFileToObject<List<MyArea>>(_File);
                if (_Areas == null)
                {
                    _Areas = new List<MyArea>()
                    {
                        new MyArea(){ AreaCode="11", AreaName="北京", PY="beijing" },
                        new MyArea(){ AreaCode="12", AreaName="天津", PY="tianjin" },
                        new MyArea(){ AreaCode="13", AreaName="河北", PY="hebei" },
                        new MyArea(){ AreaCode="14", AreaName="山西", PY="shanxi14" },
                        new MyArea(){ AreaCode="15", AreaName="内蒙古", PY="neimenggu" },
                        new MyArea(){ AreaCode="21", AreaName="辽宁", PY="liaoning" },
                        new MyArea(){ AreaCode="22", AreaName="吉林", PY="jilin" },
                        new MyArea(){ AreaCode="23", AreaName="黑龙江", PY="heilongjiang" },
                        new MyArea(){ AreaCode="31", AreaName="上海", PY="shanghai" },
                        new MyArea(){ AreaCode="32", AreaName="江苏", PY="jiangsu" },
                        new MyArea(){ AreaCode="33", AreaName="浙江", PY="zhejiang" },
                        new MyArea(){ AreaCode="34", AreaName="安徽", PY="anhui" },
                        new MyArea(){ AreaCode="35", AreaName="福建", PY="fujian" },
                        new MyArea(){ AreaCode="36", AreaName="江西", PY="jiangxi" },
                        new MyArea(){ AreaCode="37", AreaName="山东", PY="shandong" },
                        new MyArea(){ AreaCode="41", AreaName="河南", PY="henan" },
                        new MyArea(){ AreaCode="42", AreaName="湖北", PY="hubei" },
                        new MyArea(){ AreaCode="43", AreaName="湖南", PY="hunan" },
                        new MyArea(){ AreaCode="44", AreaName="广东", PY="guangdong" },
                        new MyArea(){ AreaCode="45", AreaName="广西", PY="guangxi" },
                        new MyArea(){ AreaCode="46", AreaName="海南", PY="hainan" },
                        new MyArea(){ AreaCode="50", AreaName="重庆", PY="chongqing" },
                        new MyArea(){ AreaCode="51", AreaName="四川", PY="sichuan" },
                        new MyArea(){ AreaCode="52", AreaName="贵州", PY="guizhou" },
                        new MyArea(){ AreaCode="53", AreaName="云南", PY="yunnan" },
                        new MyArea(){ AreaCode="54", AreaName="西藏", PY="xicang" },
                        new MyArea(){ AreaCode="61", AreaName="陕西", PY="shanxi61" },
                        new MyArea(){ AreaCode="62", AreaName="甘肃", PY="gansu" },
                        new MyArea(){ AreaCode="63", AreaName="青海", PY="qinghai" },
                        new MyArea(){ AreaCode="64", AreaName="宁夏", PY="ningxia" },
                        new MyArea(){ AreaCode="65", AreaName="新疆", PY="xinjiang" }
                    };
                    JsonHelper.ObjectToJsonFile(_Areas, _File);
                }
            }
            return _Areas;
        }


    }
}
